var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    page: 1,
    // 左右滑动
    currentTab: 0,

    ishave: true,   //判断有无排名
    mRankbox: [],
    lRankbox: []
  },

  /*** 点击tab切换***/
  swichNav: function (e) {
    var that = this;
    that.setData({
      currentTab: e.target.dataset.current,
      scroll_height: 0,
      page: 1,
    });
    var options = {};
    options.index = e.detail.current;
    that.onLoad(options);
  },
  /*** 滑动切换tab***/
  bindChange: function (e) {
    var that = this;
    console.log(e.detail.current);
    that.setData({
      currentTab: e.detail.current,
      scroll_height: 0,
      page: 1,
    });
    var options = {};
    options.index = e.detail.current;
    that.onLoad(options);
  },


  // 没数据是跳转点击跳转到提问页
  jumps: function () {
    var that = this;
    wx.reLaunch({
      url: '/pages/voice_box/index/index',
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    app.token_md5();
    if (options.index == undefined || options.index == 0) {
      wx.showLoading({ title: 'loading', mask: true });
      wx.request({
        url: app.url2 + "api/mRanking",
        data: {
          openid: wx.getStorageSync('openid'),
          token: wx.getStorageSync('token_md5'),
        },
        success: function (data) {
          if (data.data.code == '201') {
            that.setData(
              {
                ishave: false
              }
            );
          } else {
            that.setData(
              {
                ishave: true,
                mRankbox: data.data.result
              }
            );
          }
          wx.hideLoading();
        }
      });
    }
    if (options.index == 1) {
      wx.showLoading({ title: 'loading', mask: true });
      app.token_md5();
      wx.request({
        url: app.url2 + "api/lRanking",
        data: {
          openid: wx.getStorageSync('openid'),
          token: wx.getStorageSync('token_md5'),
        },
        success: function (data) {
          if (data.data.code == '201') {
            that.setData(
              {
                ishave: false
              }
            );
          } else {
            that.setData(
              {
                ishave: true,
                lRankbox: data.data.result
              }
            );
          }
          wx.hideLoading();
        }
      });
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})